<template>
  <div class="body">
    <div class="loginbox">
      <div class="flex con">
        <div class="right-box">
          <!-- 这里是主体部分 -->
          <div class="logon">
            <div class="logo">
              <el-image :src="websetting.sitelogoimg" :fit="'contain'" style="width: 70px;height: 78px;"></el-image>
            </div>
            <h1>设置密码</h1>
            <div class="inputtext">
              <el-form :model="form" status-icon :rules="rules" ref="form" label-width="100px" class="demo-form"
                :label-position="labelPosition">
                <el-form-item>
                  <el-input type="text" v-model="form.mobile" autocomplete="off" readonly="readonly" prefix-icon="el-icon-phone"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input type="password" v-model="form.password" autocomplete="off" placeholder="请输入新密码" prefix-icon="el-icon-lock"></el-input>
                </el-form-item>
                <el-form-item prop="confirmpwd">
                  <el-input type="password" v-model="form.confirmpwd" autocomplete="off" placeholder="请再次输入您的新密码" prefix-icon="el-icon-lock"></el-input>
                </el-form-item>
              </el-form>
              <div class="bottomtips">
                <el-checkbox v-model="checked" class="tips1">我已知悉并同意接受</el-checkbox>
                <a href="javascript:;" @click="goiframe('/admin/home/privacyPolicy/','用户隐私政策协议')">《用户隐私政策协议》</a>及<a href="javascript:;" @click="goiframe('/admin/home/regAgreement/','用户注册协议')">《用户注册协议》</a>
              </div>
              <el-button type="primary" class="button" @click="submitForm('form')">确认修改</el-button>
              <div class="e-font-12 text-center e-p-t-15">
                使用已有账号<nuxt-link :to="'/login/'">直接登录</nuxt-link>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog :title="iframe.title" :visible.sync="dialogVisible" width="1200px">
      <iframe :src="iframe.link" width="1100px" height="600px" style="border: 0;" ref="iframe"></iframe>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      // 这里也是
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.form.confirmpwd !== '') {
            this.$refs.form.validateField('confirmpwd');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.form.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        // 判断校验是否成功
        istrue: true,
        input: '',
        labelPosition: 'top',
        checked: false,
        codeImg: '',
        // 这下面的都是那个自动验证的data
        form: {
          password: '',
          confirmpwd: '',
          mobile: '',
          findcaptcha: ''
        },
        rules: {
          password: [{
            validator: validatePass,
            trigger: 'blur'
          },{
          	// 正则不能含有两边的引号
          	pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/,
          	message: '需同时含有字母和数字，长度在6-12之间',
          	trigger: 'blur'
          }],
          confirmpwd: [{
            validator: validatePass2,
            trigger: 'blur'
          }]
        },
        iframe:{
          link: '',
          title: ''
        }
      };
    },
    mounted() {
      this.form.mobile = this.$router.history.current.query.mobile;
      this.form.findcaptcha = this.$router.history.current.query.findcaptcha;
    },
    methods: {
      // 这里是那个自动验证的方法
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios.post('/User/ResetPassword',this.form).then((res) => {
              this.$message.success(res.msg);
              setTimeout(()=>{
              	this.$router.push({
                  path:"/login/"
                })
              },1000)
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      goiframe(url,title){
        this.iframe.link = url;
        this.iframe.title = title;
        this.dialogVisible = true
      }
    }
  }
</script>

<style scoped>
  .dialogPage>>>.el-dialog__body {
    padding: 0px;
  }

  .dialogPage>>>.el-dialog__header {
    padding: 20px 20px 0px;
  }
</style>
<style lang="scss" scoped>
  //   .inputitem >>> .el-form-item__label{
  //   padding: 0px;
  // }
  .dialogCode{
    .main{
        display: flex;
        justify-content: center;
        align-items: center;
        border: 1px solid var(--grey);
    }
    .inputCode{
      margin-top: 20px;
      display: flex;
      align-items: center;
      .input{

      }
      .button{

      }
    }
  }
  .dialog-text {
    padding-left: 48px;
    padding-bottom: 30px;
  }

  .body {
    background-color: var(--light)
  }

  .loginbox {
    width: 1200px;
    height: calc(100vh - 40px);
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;

    .con {
      box-shadow: 0 2px 12px 0 #0000002e;
      // height: 584px;
      .left-box{
        background-color: #f3faff;
        position: relative;

        .text-content{
          position: absolute;
          top: 0;
          width: 100%;
          padding: 93px 50px;
          box-sizing: border-box;
          h3{
            font-size: 28px;
            margin-top: 0;
            margin-bottom: 15px;
            font-weight: inherit;
          }
          .s_text{
            color: var(--gray);
            line-height: 24px;
          }
        }
      }
      .left-box-img {
        transform: scale(0.85);
        width: 470px;
        height: 100%;
      }

      .right-box {
        overflow: hidden;

        .logon {
          height: 100%;
          width: 470px;
          padding: 0px 44px 24px;

          .logo {
            width: 70px;
            height: 70px;
            margin: 0 auto;
            color: var(--red);
            font-size: 70px;
            line-height: 70px;
            padding-top: 24px;
          }
        }
      }
    }

    .header {
      height: 50px;
      width: 100%;

      .img {
        width: 100px;
        height: 50px;
        float: left;
      }
    }

    .logon {
      width: 500px;
      height: 100%;
      background-color: white;
      margin: 0 auto;
      padding: 25px 25px 24px;
      box-sizing: border-box;
      position: relative;

      h1{
        width: 100%;
        text-align: center;
        font-weight: 700;
        font-size: 24px;
        color: #283548;
      }

      .inputtext {
        margin-top: 36px;
        position: relative;

        // .inputitem{
        //   margin-bottom: 5px;
        // }
        span {
          font-size: 12px;
          color: var(--grey);
        }

        // #eyes{
        // 	position: absolute;
        // 	right: 15px;
        // 	top: 253px;
        // 	color: var(--blue);
        //   &:hover{
        //     cursor: pointer;
        //   }
        // }
        .button {
          width: 100%;
          margin: 0 auto;
          margin-top: 15px;
        }

        .bottomtips {
          font-size: 12px;

          .tips1 {}

          span {
            color: black;
          }

          .tips2 {
            text-align: center;
            font-size: 0.75rem;
            margin-top: 0.625rem;

            a {
              cursor: pointer;
            }
          }
        }
      }
    }
  }
</style>
